package com.huishu.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huishu.commons.pojo.Result;
import com.huishu.user.mapper.UserMemberMapper;
import com.huishu.user.pojo.model.UserMemberDO;
import com.huishu.user.service.UserMemberService;
import com.huishu.user.service.UserService;
import com.huishu.user.utils.AssistantContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@ljj
 * @since 2023-04-06
 */
@Service
public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMemberDO> implements UserMemberService {

    @Autowired
    private UserService userService;

    @Override
    public Result get() {
        UserMemberDO userMember = userService.getUserMemberInfo(AssistantContext.currentUser().getPhone());
        if (userMember != null) {
            LambdaQueryWrapper<UserMemberDO> queryWrapper = Wrappers.lambdaQuery(UserMemberDO.class)
                    .eq(UserMemberDO::getMobile, AssistantContext.currentUser().getPhone());
            UserMemberDO one = this.getOne(queryWrapper);
            userMember.setId(one.getId());
            this.updateById(userMember);
            return Result.success(userMember);
        }
        return Result.fail("获取失败");
    }
}
